package cn.wolfcode.util;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.Permission;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;


public class UserContext {
    public static final String USER_SESSION_NAME="USER_IN_SESSION";
    public static final String PERMISSION_SESSION_NAME="PERMISSION_IN_SESSION";

   public static HttpSession getSession(){
       ServletRequestAttributes attributes=(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
       return attributes.getRequest().getSession();
   }
   public static Employee getCurrentUser(){
       return (Employee)getSession().getAttribute(UserContext.USER_SESSION_NAME);
   }
   public static void setCurrentUser(Employee currentUser){
       getSession().setAttribute(UserContext.USER_SESSION_NAME,currentUser);
   }

   public static List<String>getCurrentPermissions(){
       return (List<String>)getSession().getAttribute(UserContext.USER_SESSION_NAME);
   }
   public static void setCurrentPermission(List<String>currentPermission){
     getSession().setAttribute(UserContext.PERMISSION_SESSION_NAME,currentPermission);
   }


}
